package com.jiangxiaofei.citycloud.mvp;

import android.content.Context;
import android.widget.Toast;

import com.blankj.utilcode.util.EmptyUtils;
import com.jiangxiaofei.citycloud.httpUtil.OnLoadDataIm;
import com.jiangxiaofei.citycloud.param.AddJobsParam;
import com.jiangxiaofei.citycloud.param.RecruitDoWorkParam;
import com.jiangxiaofei.citycloud.param.UserInfoParam;

/**
 * Created by Administrator on 2017/9/11 0011.
 */

public class RecruitPersenter implements RecruitConstant.UserInfoPersenter,
        RecruitConstant.WorkLabelPersenter, RecruitConstant.DoWorkPersenter,
        RecruitConstant.DoWorkInfoPersenter, RecruitConstant.AddJobInfoPersenter,
        RecruitConstant.UpdateJobPerssenter, RecruitConstant.GetJobListPersenter,
        RecruitConstant.GetJobInfoPersenter, RecruitConstant.GetWorkerPersenter,
        RecruitConstant.GetWorkPersenter, RecruitConstant.UpdateWorkerPersenter,
        RecruitConstant.DeleteWorkPersenter, RecruitConstant.getWorkerNumPersenter
        , RecruitConstant.getWorkNumPersenter {
    Context mContext;
    RecruitConstant.UserInfoModel userInfoModel;
    RecruitConstant.UserInfoView userInfoView;

    RecruitConstant.WorkLabelModel workLabelModel;
    RecruitConstant.WorkLabelView workLabelView;

    RecruitConstant.DoWorkView doWorkView;
    RecruitConstant.DoWorkModel doWorkModel;

    RecruitConstant.DoWorkInfoModel doWorkInfoModel;
    RecruitConstant.DoWorkInfoView doWorkInfoView;

    RecruitConstant.AddjobInfoModel addjobInfoModel;
    RecruitConstant.AddJobInfoView addJobInfoView;

    RecruitConstant.UpdateJobModel updateJobModel;
    RecruitConstant.UpdateJobView updateJobView;

    RecruitConstant.GetJobListModel getJobListModel;
    RecruitConstant.GetJobListView getJobListView;

    RecruitConstant.GetJobInfoModel getJobInfoModel;
    RecruitConstant.GetJobInfoView getJobInfoView;

    RecruitConstant.GetWorkModel getWorkModel;
    RecruitConstant.GetWorkView getWorkView;

    RecruitConstant.GetWorkerModel getWorkerModel;
    RecruitConstant.GetWorkerView getWorkerView;

    RecruitConstant.UpdateWorkerInfoModel updateWorkerInfoModel;
    RecruitConstant.UpdateWorkerInfoView updateWorkerInfoView;

    RecruitConstant.DeleteWorkModel deleteWorkModel;
    RecruitConstant.DeleteWorkView deleteWorkView;

    RecruitConstant.getWorkNumModel getWorkNumModel;
    RecruitConstant.getWorkNumView getWorkNumView;

    RecruitConstant.getWorkerNumModel getWorkerNumModel;
    RecruitConstant.getWorkerNumView getWorkerNumView;

    public RecruitPersenter(Context mContext, RecruitConstant.UserInfoView userInfoView) {
        this.mContext = mContext;
        this.userInfoView = userInfoView;
        this.userInfoModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.WorkLabelView workLabelView) {
        this.mContext = mContext;
        this.workLabelView = workLabelView;
        workLabelModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.DoWorkView doWorkView) {
        this.mContext = mContext;
        this.doWorkView = doWorkView;
        doWorkModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.DoWorkInfoView doWorkInfoView) {
        this.mContext = mContext;
        this.doWorkInfoView = doWorkInfoView;
        doWorkInfoModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.AddJobInfoView addJobInfoView) {
        this.mContext = mContext;
        this.addJobInfoView = addJobInfoView;
        addjobInfoModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.UpdateJobView updateJobView) {
        this.mContext = mContext;
        this.updateJobView = updateJobView;
        updateJobModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.GetJobListView getJobListView) {
        this.mContext = mContext;
        this.getJobListView = getJobListView;
        getJobListModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.GetJobInfoView getJobInfoView) {
        this.mContext = mContext;
        this.getJobInfoView = getJobInfoView;
        getJobInfoModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.GetWorkView getWorkView) {
        this.mContext = mContext;
        this.getWorkView = getWorkView;
        getWorkModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.GetWorkerView getWorkerView) {
        this.mContext = mContext;
        this.getWorkerView = getWorkerView;
        getWorkerModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.UpdateWorkerInfoView updateWorkerInfoView) {
        this.mContext = mContext;
        this.updateWorkerInfoView = updateWorkerInfoView;
        updateWorkerInfoModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.getWorkNumView getGetWorkView) {
        this.mContext = mContext;
        this.getWorkNumView = getGetWorkView;
        this.getWorkNumModel = new RecruitModel();
    }

    public RecruitPersenter(Context mContext, RecruitConstant.DeleteWorkView deleteWorkView) {
        this.mContext = mContext;
        this.deleteWorkView = deleteWorkView;
        this.deleteWorkModel = new RecruitModel();
    }


    public RecruitPersenter(Context mContext, RecruitConstant.getWorkerNumView getWorkerNumView) {
        this.mContext = mContext;
        this.getWorkerNumView = getWorkerNumView;
        this.getWorkerNumModel = new RecruitModel();
    }

    //登陆获取用户信息
    @Override
    public void getUserinfo() {
        if (EmptyUtils.isNotEmpty(userInfoView.getUserInfo())) {
            UserInfoParam userParam = userInfoView.getUserInfo();
            userInfoModel.getUserInfo(mContext, userParam.getName(), userParam.getPassword(), new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        userInfoView.setData(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    //    获取工作标签
    @Override
    public void getWorkLabel() {
        workLabelModel.getWorkLabel(mContext, new OnLoadDataIm() {
            @Override
            public void onSuccess(Object o, int resultCode) {

            }

            @Override
            public void onSuccess(Object o, String message, int resultCode) {
                if (EmptyUtils.isNotEmpty(o)) {
                    workLabelView.setData(o);
                }
            }

            @Override
            public void onFailure(String msg, int resultCode) {

            }
        });
    }

    //提交干活信息
    @Override
    public void postDoWork() {
        if (EmptyUtils.isNotEmpty(doWorkView.postDoWork())) {
            RecruitDoWorkParam recruitDoWorkParam = doWorkView.postDoWork();
            doWorkModel.postDoWork(mContext, recruitDoWorkParam.getId()
                    , recruitDoWorkParam.getIntroduce(), recruitDoWorkParam.getCoverage()
                    , recruitDoWorkParam.getLat(), recruitDoWorkParam.getLog(), recruitDoWorkParam.getRole()
                    , recruitDoWorkParam.getFreetime(), new OnLoadDataIm() {
                        @Override
                        public void onSuccess(Object o, int resultCode) {

                        }

                        @Override
                        public void onSuccess(Object o, String message, int resultCode) {
                            if (EmptyUtils.isEmpty(message)) {
                                doWorkView.publishDoWork();
                            }
                        }

                        @Override
                        public void onFailure(String msg, int resultCode) {

                        }
                    });
        }
    }

    //获取求职信息
    @Override
    public void getDoWorkInfo() {
        if (!EmptyUtils.isEmpty(doWorkInfoView.getDoWorkInfo())) {
            int userId = doWorkInfoView.getDoWorkInfo();
            doWorkInfoModel.getDoWorkInfo(mContext, userId, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        doWorkInfoView.getDoworkSuccess(o);

                    } else {
                        Toast.makeText(mContext, "获取信息失败", Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    //添加招聘信息
    @Override
    public void addJobInfo() {
        if (EmptyUtils.isNotEmpty(addJobInfoView.addJobInfo())) {
            AddJobsParam addJobsParam = addJobInfoView.addJobInfo();
            addjobInfoModel.addJobInfo(mContext, addJobsParam.getUserId(), addJobsParam.getRole()
                    , addJobsParam.getWorkspace(), addJobsParam.getWorkTime(), addJobsParam.getOther()
                    , addJobsParam.getPay(), addJobsParam.getPhone(), addJobsParam.getContacts(), addJobsParam.getLat()
                    , addJobsParam.getLog(), addJobsParam.getDescription(), new OnLoadDataIm() {
                        @Override
                        public void onSuccess(Object o, int resultCode) {

                        }

                        @Override
                        public void onSuccess(Object o, String message, int resultCode) {
                            addJobInfoView.setData(o);
                        }

                        @Override
                        public void onFailure(String msg, int resultCode) {

                        }
                    });
        }
    }


    //更新招聘信息
    @Override
    public void updateJob() {
        if (EmptyUtils.isNotEmpty(updateJobView.updateJob())) {
            AddJobsParam param = updateJobView.updateJob();
            updateJobModel.updateJob(mContext, param, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    updateJobView.onSuccess();
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    //获取工作列表
    @Override
    public void getJobList() {
        if (getJobListView.getJobList() > 0) {
            getJobListModel.getJobList(mContext, getJobListView.getJobList(), new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getJobListView.setData(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    //获取工作详情
    @Override
    public void getJobInfo() {
        if (getJobInfoView.getJobInfo() > 0) {
            getJobInfoModel.getJobInfo(mContext, getJobInfoView.getJobInfo(), new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getJobInfoView.onSuccess(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }


    //获取工人坐标
    @Override
    public void getWorker() {
        if (!(getWorkerView.getWorkerRole() < 0)) {
            getWorkerModel.getWorker(mContext, getWorkerView.getWorkerRole(), new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getWorkerView.onSuccessWorker(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {
                    getWorkerView.onNull();
                    Toast.makeText(mContext, "没有找到相关信息", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }


    //获取工作坐标
    @Override
    public void getWork() {
        if (!(getWorkView.getWorkRole() < 0)) {
            getWorkModel.getWork(mContext, getWorkView.getWorkRole(), new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getWorkView.onSuccessWork(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {
                    getWorkView.onNull();
                    Toast.makeText(mContext, "没有找到相关信息", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    //更改工人信息
    @Override
    public void updateWorkerInfo() {
        final RecruitDoWorkParam recruitDoWorkParam = updateWorkerInfoView.updateWorkerInfo();
        if (EmptyUtils.isNotEmpty(recruitDoWorkParam)) {
            updateWorkerInfoModel.updateWorkerInfo(mContext, recruitDoWorkParam, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    updateWorkerInfoView.updateSuccess();
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    //删除工作列表
    @Override
    public void DeleteWork() {
        String id = deleteWorkView.deleteWorkId();
        if (EmptyUtils.isNotEmpty(id)) {
            deleteWorkModel.deleteWork(mContext, id, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {
                    deleteWorkView.onDeleteSuccess();
                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    //获取工人数量
    @Override
    public void getWorkerNum() {
        getWorkerNumModel.getWorkerNum(mContext, new OnLoadDataIm() {
            @Override
            public void onSuccess(Object o, int resultCode) {

            }

            @Override
            public void onSuccess(Object o, String message, int resultCode) {
                if (EmptyUtils.isNotEmpty(o)) {
                    getWorkerNumView.onGetWorkerNumSuccesss(o);
                }
            }

            @Override
            public void onFailure(String msg, int resultCode) {

            }
        });
    }

    //获取工作数量
    @Override
    public void getWorkNum() {
        getWorkNumModel.getWorkNum(mContext, new OnLoadDataIm() {
            @Override
            public void onSuccess(Object o, int resultCode) {

            }

            @Override
            public void onSuccess(Object o, String message, int resultCode) {
                if (EmptyUtils.isNotEmpty(o)) {
                    getWorkNumView.onGetWorkNumSuccess(o);
                }
            }

            @Override
            public void onFailure(String msg, int resultCode) {

            }
        });
    }
}
